package com.hudsonmq.spring.impl.produce.helper;

import com.hudson.core.concurrent.CallBack;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;

public class SendMessageSyncHelper {

    private static final ConcurrentHashMap<Long, CompletableFuture<Boolean>> syncPromise = new ConcurrentHashMap<>();
    private static final ConcurrentHashMap<Long, SendCallBack> ASyncPromise = new ConcurrentHashMap<>();
    private static final ConcurrentHashMap<Long, CallBack> ASyncPromiseCallBack = new ConcurrentHashMap<>();


    public static void put(long messageId, CompletableFuture future) {
        syncPromise.put(messageId, future);
    }

    public static void removeFuture(long messageId) {
        syncPromise.remove(messageId);
    }

    public static CompletableFuture<Boolean> getFuture(long messageId) {
        return syncPromise.get(messageId);
    }

    public static void put(long messageId, SendCallBack callBack) {
        ASyncPromise.put(messageId, callBack);
    }

    public static void put(long messageId, CallBack callBack) {
        ASyncPromiseCallBack.put(messageId, callBack);
    }

    public static void remove(long messageId) {
        ASyncPromise.remove(messageId);
    }

    public static SendCallBack getCallback(long messageId) {
        return ASyncPromise.get(messageId);
    }

    public static CallBack getCallback1(long messageId) {
        return ASyncPromiseCallBack.get(messageId);
    }
}
